<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="connect">连接</button>
    <button id="send">发送数据</button>
    <div id="recv"></div>

    <script>
        let connect =document.querySelector('#connect')
        let send = document.querySelector('#send')
        let recv = document.querySelector('#recv')
        let ws=null
        connect.onclick=function(){
              ws =new WebSocket('ws://localhost:9998')
             ws.onopen=()=>{
                console.log('连接成功。。。。')
             }
             ws.onclose=()=>{
                console.log('连接失败。。。。')
             }
             ws.onmessage=msg=>{
                console.log('接受到数据了',msg.data)
                recv.innerHTML = msg.data
             }
             
        }
        let data=[1,2,3,{a:123}]

            send.onclick =function(){
               ws.send(JSON.stringify({
                  action:'getDatas',
                  socketType:'hotData',
                  chartName:'hot',
                  value:''
               }))
            }
       

    </script>
</body>
</html>